/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniminuto.arqSw.videominuto.DAO;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import co.edu.uniminuto.arqSw.videominuto.Hibernate.HibernateUtil;
import co.edu.uniminuto.arqSw.videominuto.Hibernate.Video;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;

/**
 *
 * @author JULIAN
 */
public class RecientesDAO {
    Session session = null;
    
    
    public RecientesDAO(){
     this.session = HibernateUtil.getSessionFactory().openSession();
                         }
    
    public List<Video> traeEstrenos() {
        

        List<Video> estreno = new ArrayList<Video>();      
    try{
   
    Transaction tx = session.beginTransaction();
    tx.begin();
   Criteria c = session.createCriteria(Video.class);
   c.addOrder(Order.desc("anoReproduccion"));
   c.setFirstResult(0);
   c.setMaxResults(5);
   estreno=c.list();
   tx.commit();
}catch(Exception e){
e.printStackTrace();
}
//session.close();
return estreno;
    }

}
